<?php
//  header("Content-Type:multipart/form-data;charset=UTF-8");
header('Access-Control-Allow-Origin:*');
$data_arr = array();
if($_FILES){
    $filename = './import/'.time().rand().'.txt';
    move_uploaded_file($_FILES['project_file']['tmp_name'],$filename);
    sleep(0.5);
    $file = fopen($filename,'r');
    while($row = fgets($file)){   // 这个地方注意，被读取文件的一行不能太长
        array_push($data_arr,$row);
    }
    $db_con = mysqli_connect('localhost','root','');
    $result = mysqli_query($db_con,'set names utf8');
    $result = mysqli_query($db_con,'use sx_control');
   
    for($i=1;$i<=count($data_arr);$i++){
        $data = json_decode($data_arr[$i],JSON_UNESCAPED_UNICODE);
        $row_name = $data['name'];
        $row_content = $data['content'];
        $row_version = $data['version'];
        $row_ctime = $data['c_time'];
        $row_mtime = $data['m_time'];
        $sql = "insert into project values(default , '$row_name','$row_content','$row_version','$row_ctime','$row_mtime')";
        print_r ($sql);
        $result = mysqli_query($db_con,$sql);
    }
    mysqli_close($db_con);
    fclose($file);
}
?>